/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package planspiel.panels.subpanels;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import planspiel.GameRoundController;
import planspiel.panels.GameScreen;

/**
 *
 * @author Administrator
 */
public class GameNavigation extends JPanel {

	private static final long serialVersionUID = -4879961132870706274L;
	private GameScreen gameScreen = null;
    
        /**
         * 
         * @param gameScreen
         */
        public GameNavigation(GameScreen gameScreen) {
        this.gameScreen = gameScreen;
        initDisplay();
    }
    
    private void initDisplay() {
        GroupLayout layout = new GroupLayout(this);
        this.setLayout(layout);
        
        JButton vacancy = new JButton("Vacancy");
        JButton platforms = new JButton("Platforms");
        JButton candidates = new JButton("Candidates");
        JButton messages = new JButton("Messages");
        JButton tip = new JButton("Tips");

        //Enable / Disable buttons
        vacancy.setEnabled(gameScreen.getGame().getCurrentGameRoundController().isVacancyButtonEnabled());
        platforms.setEnabled(gameScreen.getGame().getCurrentGameRoundController().isPlatformButtonEnabled());
        candidates.setEnabled(gameScreen.getGame().getCurrentGameRoundController().isCandidatesButtonEnabled());
        messages.setEnabled(gameScreen.getGame().getCurrentGameRoundController().isMessagesButtonEnabled());
        tip.setEnabled(gameScreen.getGame().getCurrentGameRoundController().isTipsButtonEnabled());

        //Highlight current selected button
        if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() == GameRoundController.VACANCYSTAGE){
            vacancy.setBackground(Color.LIGHT_GRAY);
        } else if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() == GameRoundController.PLATFORMSTAGE){
            platforms.setBackground(Color.LIGHT_GRAY);
        } else if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() == GameRoundController.CANDIDATESTAGE){
            candidates.setBackground(Color.LIGHT_GRAY);
        } else if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() == GameRoundController.MESSAGESTAGE){
            messages.setBackground(Color.LIGHT_GRAY);
        } else if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() == GameRoundController.TIPSTAGE){
            tip.setBackground(Color.LIGHT_GRAY);
        }
        
        vacancy.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
 
if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage
() != GameRoundController.VACANCYSTAGE){
 
gameScreen.getGame().getCurrentGameRoundController().setSelectedGameStage(GameRoundController.VACANCYSTAGE);
                    gameScreen.getGame().initDisplay();
                }
            }
        });

        
        
        
        vacancy.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() != GameRoundController.VACANCYSTAGE){
            		gameScreen.getGame().getCurrentGameRoundController().setSelectedGameStage(GameRoundController.VACANCYSTAGE);
            		gameScreen.getGame().initDisplay();
            	}
            }
        });

        platforms.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() != GameRoundController.PLATFORMSTAGE){
            		gameScreen.getGame().getCurrentGameRoundController().setSelectedGameStage(GameRoundController.PLATFORMSTAGE);
            		gameScreen.getGame().initDisplay();
            	}
            }
        });     
        
        candidates.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() != GameRoundController.CANDIDATESTAGE){
            		gameScreen.getGame().getCurrentGameRoundController().setSelectedGameStage(GameRoundController.CANDIDATESTAGE);
            		gameScreen.getGame().initDisplay();
            	}
            }
        });

        messages.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() != GameRoundController.MESSAGESTAGE){
            		gameScreen.getGame().getCurrentGameRoundController().setSelectedGameStage(GameRoundController.MESSAGESTAGE);
            		gameScreen.getGame().initDisplay();
            	}
            }
        });            

        tip.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
            	if(gameScreen.getGame().getCurrentGameRoundController().getSelectedGameStage() != GameRoundController.TIPSTAGE){
            		gameScreen.getGame().getCurrentGameRoundController().setSelectedGameStage(GameRoundController.TIPSTAGE);
            		gameScreen.getGame().initDisplay();
            	}
            }
        });            
        
        layout.setHorizontalGroup(
            layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                .addComponent(vacancy, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(platforms, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(candidates, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(messages, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(tip, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        layout.setVerticalGroup(
            layout.createSequentialGroup()
                .addComponent(vacancy, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(platforms, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(candidates, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(messages, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(tip, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }
    
}
